package com.ehaoyao.web;

import com.ehaoyao.entity.Order;
import com.ehaoyao.produce.KafkaProduce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * <dl>
 * <dt>KafkaDemo</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2006</dd>
 * <dd>CreateDate: 2020/5/12</dd>
 * </dl>
 *
 * @author zhangyp
 */
@RestController
@RequestMapping("/kafka/")
public class KafkaApi {

    @Autowired
    private KafkaProduce kafkaProduce;

    @RequestMapping("/{id}/{price}")
    public String getOrderPay(@PathVariable(value = "id") String id,@PathVariable(value = "price") BigDecimal price){
       for(int i = 1 ;i<=Integer.valueOf(id);i++){
           Order order = new Order();
           order.setId(i);
           order.setPrice(price.multiply(BigDecimal.valueOf(i)));
           kafkaProduce.send(order);
       }
        return  id+"提交成功";
    }
}
